package com.qaml.mes.device.domain.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.earth.page.PageResponse;
import com.qaml.mes.device.api.EqpRepairService;
import com.qaml.mes.device.dao.EqpRepairDO;
import com.qaml.mes.device.repository.EqpRepairRepository;
import com.qaml.mes.device.domain.convert.EqpRepairConvert;
import com.qaml.mes.device.dto.eqp.EqpRepairDTO;
import com.qaml.mes.device.vo.eqp.EqpRepairVO;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 设备维修表 服务实现类
 * </p>
 *
 * @author leikai
 * @since 2024-03-04
 */
@Service
public class EqpRepairServiceImpl implements EqpRepairService {

    @Resource
    private EqpRepairRepository eqpRepairRepository;

    /**
     * 设备维修列表
     *
     * @param eqpRepairDTO
     * @return
     */
    @Override
    public PageResponse<EqpRepairVO> repairList(EqpRepairDTO eqpRepairDTO) {

        // 1,获取分页对象
        IPage<EqpRepairDO> repairVOIPage = eqpRepairRepository.repairList(eqpRepairDTO.getPage(), eqpRepairDTO.getPageSize(), eqpRepairDTO);
        // 2,判断对象是否为空
        if (repairVOIPage == null || CollectionUtils.isEmpty(repairVOIPage.getRecords())) {
            return new PageResponse<>(0, null, eqpRepairDTO);
        }
        // 3,获取记录，并进行转换
        List<EqpRepairDO> records = repairVOIPage.getRecords();
        List<EqpRepairVO> eqpRepairVOList = EqpRepairConvert.INSTANCE.dos2VOS(records);
        // 4,返回相关内容
        return new PageResponse<>(repairVOIPage.getTotal(), eqpRepairVOList, eqpRepairDTO);
    }
}
